﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NewGlobalBizAssist.Lib
{
    public class FindUpdateEventArgs : EventArgs
    {
        // add local member variable to hold text
        private readonly string mselectedvalue;

        // class constructor
        public FindUpdateEventArgs(string selectedvalue)
        {
            mselectedvalue = selectedvalue;
        }

        // Properties - Accessible by the listener

        public string SelectedValue
        {
            get
            {
                return mselectedvalue;
            }
        }


    }

    public class Common
    {

        public static double GetSafeDbl(string val)
        {
            double d;
            if (val == null)
                return 0;
            Double.TryParse(val, out d);
            return d;
        }


        public static double GetSafeDbl(object val)
        {
            double d;
            if (val == null)
                return 0;
            Double.TryParse(val.ToString(), out d);
            return d;
        }

        public static int GetSafeInt(string val)
        {
            int d;
            if (val == null)
                return 0;
            int.TryParse(val, out d);
            return d;
        }


        public static int GetSafeInt(object val)
        {
            int d;
            if (val == null)
                return 0;
            int.TryParse(val.ToString(), out d);
            return d;
        }




        public static DateTime? GetSafeDate(object val)
        {
            try
            {
                DateTime d = DateTime.Now;
                if (val == null)
                    return null;
                DateTime.TryParse(val.ToString(), out d);
                return d;
            }
            catch
            {
                return null;
            }
        }

        public static DateTime? GetSafeDate(string val)
        {
            try
            {
                DateTime d = DateTime.Now;
                if (val == null)
                    return null;
                DateTime.TryParse(val, out d);
                return d;
            }
            catch
            {
                return null;
            }
        }

        public static string GetSafeString(object val)
        {
            if (val == null)
                return string.Empty;
            return val.ToString();
        }

        public static string GetSafeString(string val)
        {
            if (val == null)
                return string.Empty;
            return val;
        }

        public static string StrSQL(string val)
        {
            return val.Replace("'", "''");
        }
    }

}